//实体对象
function Entity(param){
	 this.selectUrl=param.selectUrl;
	 this.addUrl=param.addUrl;
	 this.deleteUrl=param.deleteUrl;
	 this.updateUrl=param.updateUrl;
	 this.keyWord=param.keyWord;
	 this.searchBin=param.searchBin;
	 this.addBin=param.addBin;
	 this.totalRowsId=param.totalRowsId;
	 this.currentPageId=param.currentPageId;
	 this.startRowId=param.startRowId;
	 this.endRowId=param.endRowId;
	 this.limitId=param.limitId;
	 this.prvePageId=param.prvePageId;
	 this.nextPageId=param.nextPageId;
	 this.currentPage=1;
	 this.pageSize=2;
	 this.reload=param.reload;
}
//查询
Entity.prototype.select=function(){
	var that=this;
	console.log(that.selectUrl);
	$.ajax({
		url:"./"+that.selectUrl,
		type:'get',
		data:{
			keyword:$(that.keyWord).val(),
			currentPage:that.currentPage,
			pageSize:2
		},
		dataType:'json',
		success:function(result){
			if(result.code==200 && result.data!=null){
				that.reload(result.data.list);
				var aaa=that.totalRowsId;
				$(that.totalRowsId).html(result.data.total);
				$(that.startRowId).html(result.data.startRow);
				$(that.endRowId).html(result.data.endRow);
				$(that.limitId).html(result.data.size);
				$(that.currentPageId).html(result.data.currentPage);
			}
		},
		error:function(e){
			console.log("请求后台出错"+JSON.stringify(e));
		}
	});
}
Entity.prototype.bindEvent=function(){
	var that=this;
	
	$(that.searchBin).click(function(){
		that.select();
	});
	
	$(that.addBin).click(function(){
		that.add();
	});
	
	//上一页
	$(that.prvePageId).click(function(){
		that.prvePage();
	});
	
	//下一页
	$(that.nextPageId).click(function(){
		that.nextPage();
	});
}

//上一页
Entity.prototype.prvePage=function(){
	var currentPage=this.currentPage;
	var pageSize=parseInt($(this.limitId).text());
	if(currentPage>1){
		currentPage-=1;
	}
	this.currentPage=currentPage;
	this.pageSize=pageSize
	this.select();
}
//下一页
Entity.prototype.nextPage=function(){
	var currentPage=this.currentPage;
	var totalRowsId=parseInt($(this.totalRowsId).text());
	if(currentPage<Math.ceil(totalRowsId/this.pageSize)){
		currentPage+=1;
	}
	this.currentPage=currentPage;
	this.select();
}


//新增
Entity.prototype.add=function(){ 
	var that=this;
	layer.open({
		title:'添加课程',
		type:2,
		shadeClose:true,
		area:['30%','40%'],
		content:'./'+that.addUrl,
		scrollbar :true
	});
	
}
//删除
Entity.prototype.deleteById=function(id){ 
	 
}
//修改
Entity.prototype.updateById=function(id){ 
	var that=this;
	layer.open({
		title:'修改课程',
		type:2,
		shadeClose:true,
		area:['30%','40%'],
		content:'./'+that.updateUrl,
		scrollbar :true
	});
}